package sing.rabbit.direct.consumer.config;

import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import sing.rabbit.direct.consumer.consume.DirectQueueListener3;

import static sing.rabbit.direct.common.DirectConfigurations.DIRECT_QUEUE_NAME_1;

/**
 * @author xing
 * @date 2022/9/8 7:47
 */
@Profile("sample_3")
@Configuration
public class DirectConsumeConfiguration {
    @Bean
    public DirectMessageListenerContainer directMessageListenerContainer(CachingConnectionFactory rabbitConnectionFactory, DirectQueueListener3 directQueueListener3) {
        DirectMessageListenerContainer container = new DirectMessageListenerContainer();
        container.setConnectionFactory(rabbitConnectionFactory);
        container.setQueueNames(DIRECT_QUEUE_NAME_1);
        container.setMessageListener(directQueueListener3);
        container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
        // qos
        // 告诉代理在单个请求中向每个使用者发送多少消息。通常可以将其设置得很高以提高吞吐量。
        container.setPrefetchCount(5);
        return container;
    }


}
